package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.RestStripUtils;
import io.renren.modules.generator.dao.RestDao;
import io.renren.modules.generator.entity.RestEntity;
import io.renren.modules.generator.service.RestService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;


@Service("restService")
public class RestServiceImpl extends ServiceImpl<RestDao, RestEntity> implements RestService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<RestEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("rest_user_id", params.get("userId"));
        if (Objects.nonNull(params.get("startTime")) && Objects.nonNull(params.get("endTime"))) {
            wrapper.between("rest_time", params.get("startTime"), params.get("endTime"));
        }
        IPage<RestEntity> page = this.page(
                new Query<RestEntity>().getPage(params), wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public String getRestStrip(Integer restId) {
        RestEntity restEntity = baseMapper.selectById(restId);
        return new RestStripUtils().graphicsGeneration(restEntity);
    }

}
